home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12134 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.4 KB

  1. Path: news.cais.com!black
  2. From: afbarnes@livnet.com (Andre F. Barnes)
  3. Newsgroups: comp.lang.c++
  4. Subject: MS Visual C ++ 1.52  Problem --- Global Variables
  5. Date: Mon, 18 Mar 96 16:08:28 GMT
  6. Organization: Capital Area Internet Service info@cais.com 703-448-4470
  7. Message-ID: <4ik1qv$15q@news.cais.com>
  8. NNTP-Posting-Host: black.livnet.com
  9. Keywords: DLL,  MFC
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. HELP!  HELP!  HELP!  with Microsoft Visual C 1.52!!!!!!
  13.  
  14. Howdy out there.  
  15.  
  16. I need some help with an MSVC 1.52 DLL (callback) memory issue.  Any 
  17. suggestions, known related bugs, or solutions would be appreciated.
  18.  
  19. THE PROBLEM: 
  20. I am writing a standard (i.e. not extended) DLL for MSVC 1.52.  Part of the 
  21. routines for my DLL are contained in a separate .lib project.  Inside this 
  22. (.lib) project I am trying to use a modular variable.  I do not have any 
  23. problems with this modular variable until I try to reference it from within 
  24. a callback function.  OK, Am I starting to confuse you yet? 
  25.  
  26. DIAGRAM:  (I hope your reader uses a STATIC sized font)
  27. EXE -> my.DLL -> my library -> third party.DLL
  28.                        ^              |
  29.                        \______________/
  30.  
  31. As the diagram shows.  My DLL calls a function that is inside my library, 
  32. which I'll call Start().  That function in turn calls a third party DLL 
  33. function, call it THIRD_PARTY_func().  The third party DLL function will in 
  34. turn call my callback function, call it CallbackFunc().  
  35.  
  36. OK, After ALL that, the problem occurs.  I have a global long variable that 
  37. I now want to access from WITHIN my CallbackFunc() (see below).  However, no 
  38. matter what I do, the CallbackFunc() does not seem to know WHERE the data 
  39. segment for that variable is.  The code compiles and runs with no problems, 
  40. but the global long value never actually changes.  
  41.  
  42. I know that the variable should change because I have stepped through the 
  43. debugger NUMEROUS times.  Anyway, some code snippets are below to help you 
  44. understand what I am referring to.
  45.  
  46. CODE SNIPPETS:
  47. typedef long (far pascal far *CallbackTypedef)();
  48. long gv_long;
  49.  
  50. Start()
  51. ..
  52.   FARPROC MyCallback = MakeProcInstance((FARPROC)CallbackFunc, hInst);
  53.   THIRD_PARTY_set_callback(id, CONSTANT, (CallbackTypedef)MyCallback);
  54.   THIRD_PARTY_func(id);
  55.   THIRD_PARTY_reset_callback(id, CONSTANT, REVERT_TO_DEFAULT);
  56.   FreeProcInstance(MyCallback);
  57. ..
  58. }
  59.  
  60. long far pascal _export CallbackFunc(long far *plong)
  61. {
  62.   gv_long = *plong;
  63. }
  64.  
  65. NOTES:
  66. I think the above should be most of the snippets that are necessary to 
  67. understand what is happening.  This problem is a DOOZY.  
  68.  
  69. Note that I have no problem setting the global variable outside of the 
  70. callback function.  In addition, I have other callbacks like an event 
  71. handler for a simple C dialog that has similiar problems.
  72.  
  73. I tried making the global static, using an access function to access the 
  74. global, using a static long var within the scope of the access function. 
  75.  
  76. I have played with many of the compiler settings, all to no avail.  
  77.  
  78. FINAL NOTES:
  79. Just a few things that may help understand my environment.  I am running Win 
  80. 3.1 and MSVC 1.52. I am using C++ and MFC in both mydll and mylib (but I am 
  81. NOT interfacing my dll through classes - i.e. no extended DLL stuff).  I 
  82. have the .lib and the .dll compiled using the "SS != DS, DS NOT loaded on 
  83. function entry" option, and ALL projects are compiled with a large memory 
  84. model. 
  85.  
  86. PLEASE HELP!
  87.  
  88. If you have any information on the matter please email me at 
  89. afbarnes@livnet.com   Thanks!!!
  90.